package com.hina.rec.endpoint.system;

import cn.dev33.satoken.annotation.SaIgnore;
import com.hina.rec.application.service.system.SettleDetailService;
import com.hina.rec.common.model.IdReq;
import com.hina.rec.common.model.Result;
import com.hina.rec.endpoint.req.system.SettleDetailPageReq;
import com.hina.rec.endpoint.req.system.SettleDetailSaveReq;
import com.hina.rec.endpoint.req.system.SettleDetailUpdateReq;
import com.hina.rec.endpoint.res.base.PageRes;
import com.hina.rec.endpoint.res.system.SettleDetailRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 结算明细管理接口
 *
 * @author liaosp
 * @date 2024-01-05
 */
@Tag(name = "结算明细管理接口")
@RestController
@RequestMapping("/settle/detail")
@RequiredArgsConstructor
@SaIgnore
public class SettleDetailController {

    private final SettleDetailService settleDetailService;

    @PostMapping("/save")
    @Operation(summary = "创建结算明细")
    public Result<Boolean> save(@RequestBody @Valid SettleDetailSaveReq req) {
        return Result.success(settleDetailService.save(req));
    }

    @PostMapping("/update")
    @Operation(summary = "更新结算明细")
    public Result<Boolean> update(@RequestBody @Valid SettleDetailUpdateReq req) {
        return Result.success(settleDetailService.update(req));
    }

    @PostMapping("/delete")
    @Operation(summary = "删除结算明细")
    public Result<Boolean> delete(@RequestBody @Valid IdReq req) {
        return Result.success(settleDetailService.delete(req.getId()));
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询结算明细")
    public Result<PageRes<SettleDetailRes>> page(@RequestBody @Valid SettleDetailPageReq req) {
        return Result.success(settleDetailService.page(req));
    }

    @PostMapping("/detail")
    @Operation(summary = "获取结算明细详情")
    public Result<SettleDetailRes> detail(@RequestBody @Valid IdReq req) {
        return Result.success(settleDetailService.detail(req));
    }

    @PostMapping("/import")
    @Operation(summary = "导入结算明细")
    public Result<Boolean> importExcel(@RequestParam("file") MultipartFile file) throws IOException {
        return Result.success(settleDetailService.importExcel(file));
    }

    @GetMapping("/export")
    @Operation(summary = "导出结算明细")
    public void exportExcel(HttpServletResponse response, SettleDetailPageReq req) throws IOException {
        settleDetailService.exportExcel(response, req);
    }
}